<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler'>
      <f-search-form-item label='开始日期' type='range' name='beginDate' />
      <f-search-form-item label='订单编号' name='orderNo' />
      <f-search-form-item label='收货地址' name='customAddress' />
    </f-search-form>
    <f-table ref='table' rowKey='orderId' :tableColumns='columns' :showSetting='false' :scroll='{x:true}' :multiple='true' :operator='operator' :showMultipleBtn='false' :params='queryParam' :api='api.hyorder' handler='hyWaybillTab5ListHandler'>
        <span slot='sendType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
            <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
            <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
            <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
        </span>
      <span slot='sendState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未发货</a-tag>
            <a-tag color='purple' v-if='text==1'>已提单</a-tag>
        </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a href='javascript:;' @click='setOutPrintTag(record)'>恢复打印</a>
          </template>
        
        </span>
    </f-table>
    <FlymePrintView ref='preView' />
  </div>
</template>
<script>
import api from "../../js/api"
import FlymePrintView from "@/components/Flyme/FlymePrintDesigner/preview"

export default {
  name: "Tab5",
  components: { FlymePrintView },
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "批量打印",
      that: this,
      batch: true,
      icon:"printer",
      handler: (table, that) => {
        let selectIds = table.selectedRowKeys
        if (selectIds.length > 0) {
          this.batchPrint(selectIds)
        } else {
          that.$message.error("请选择打印数据")
        }
      }
    })
    operator.push({
      name: "合并打印",
      that: this,
      icon:"printer",
      batch: true,
      handler: (table, that) => {
        let selectIds = table.selectedRowKeys
        if (selectIds.length > 0) {
          this.mergePrint(selectIds)
        } else {
          that.$message.error("请选择合并打印数据")
        }
      }
    })
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      activeKey: "0",
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "出库单号",
          align: "left",
          width: "120px",
          dataIndex: "outOrderNo"
        },
        {
          title: "单据日期",
          align: "left",
          width: "120px",
          dataIndex: "sendDate"
        },
        {
          title: "部门",
          align: "left",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "center",
          width: "100px",
          dataIndex: "saleManName"
        },
        {
          title: "单位名称",
          align: "left",
          ellipsis: true,
          width: "130px",
          dataIndex: "customName"
        },
        {
          title: "联系人",
          align: "left",
          width: "100px",
          dataIndex: "customUserName"
        },
        {
          title: "联系电话",
          align: "left",
          width: "100px",
          dataIndex: "customUserTel"
        },
        {
          title: "收货地址",
          align: "left",
          width: "150px",
          dataIndex: "customAddress"
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "150px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator,
      processImageVisible: false,
      processInstanceId: null
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    //打印预览
    printView(order) {
      this.http.post(this, {
        url: api.hyorder.getOutOrderPrint,
        data: {
          orderId: order.orderId
        },
        success: (me, data) => {
          let template = data.template
          let printDate = data.dataList[0]
          let printTemplate = JSON.parse(template)
          this.$refs.preView.printView(printTemplate, printDate, 200)
        }
      })
    },
    
    /**
     * 恢复出库单打印
     * @param orderIds
     */
    setOutPrintTag(record) {
      this.http.confirm(this, {
        content: "确认恢复打印吗?",
        url: api.hyorder.setOutPrintTag,
        data: {
          orderId: record.orderId,
          outPrintTag: 0
        },
        success: (me, data) => {
          this.$message.success("操作成功")
          this.onLoad()
        }
      })
    },
    changeHandler(activeKey) {
      this.activeKey = activeKey
      this.$refs.table.refresh(true, { activeKey: this.activeKey })
    },
  }
}
</script>
